{% extends 'bootstrap/base.html' %}
{% import "bootstrap/wtf.html" as wtf %}

{%block title%}学生信息管理系统{% endblock %}

{% block navbar %}
<nav class="navbar navbar-default">
    <div class="container">
        <div class="navbar-header">
            <a class="navbar-brand" href="{{ url_for('index') }}">学生信息管理系统</a>
        </div>
        <div class="navbar-collapse">
            <ul class="nav navbar-nav">
                <li><a href="{{ url_for('index') }}">首页</a></li>
                {% if current_user.is_authenticated and current_user.role == 'admin' %}
                    <li><a href="{{ url_for('new_stud') }}">新增学生</a></li>
                {% endif %}
            </ul>
            <ul class="nav navbar-nav navbar-right">
                {% if current_user.is_authenticated %}
                    <li><span class="navbar-text">欢迎，{{ current_user.username }}</span></li>
                    <li><a href="{{ url_for('logout') }}">登出</a></li>
                {% else %}
                    <li><a href="{{ url_for('login') }}">登录</a></li>
                    <li><a href="{{ url_for('register') }}">注册</a></li>
                {% endif %}
            </ul>
        </div>
    </div>
</nav>
{% endblock %}

{%block content%}
<div class="container">
    {% with messages = get_flashed_messages() %}
        {% if messages %}
            {% for message in messages %}
                <div class="alert alert-info" role="alert">{{ message }}</div>
            {% endfor %}
        {% endif %}
    {% endwith %}
    
    <div class="page-header">
    <h1>Student Records</h1> 
    <div>
        <a href="{{ url_for('index') }}" class="btn btn-primary btn-xs">所有学生</a>
        {% for m in majors %}
            <a href="{{ url_for('filter_by_major', major_id=m.id) }}" class="btn btn-default btn-xs">{{ m.major_name }}</a>
        {% endfor %}
    </div>
</div>

<div class="container">
    <h4>当前共有{{studs|length}}名学生</h4>
    {% if current_user.is_authenticated and current_user.role == 'admin' %}
        <a class = "btn btn-primary" href="{{ url_for('new_stud') }}">新增学生</a>
    {% endif %}
    <div>
        {%for stud in studs%} 
        <div>
            <p style="margin:10px;">
                <strong style="font-family: '楷体';"> {{stud.name}}  </strong>
                {% if stud.major %}
                    <a class="btn btn-success btn-xs" href="{{url_for('major_information', major_name=stud.major.major_name)}}">{{ stud.major.major_name }}</a>
                {% else %}
                    <span class="label label-default">未分配专业</span>
                {% endif %}
            </p>
            {% if current_user.is_authenticated and current_user.role == 'admin' %}
                <a class="btn btn-info" href="{{url_for('edit_stud',stu_id=stud.id)}}">编辑</a> 
                <a class="btn btn-danger" href="{{url_for('del_stud',stud_id=stud.id)}}">删除</a> 
            {% endif %}
        </div>
        {%endfor%}
    </div>
</div>
{%endblock%}